﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace KduneeShaders
{
    /// <summary>
    /// Shader mapowania nierówności - algorytmem Normal, bądź Parallax mapping
    /// </summary>
    public class BumpShader : GeneralShader
    {
        /// <summary>
        /// Połyskliwość - wykładnik w równaniu na specular
        /// </summary>
        public float Shininess
        {
            get { return this.Parameters["shininess"].GetValueSingle(); }
            set { this.Parameters["shininess"].SetValue(value); }
        }

        /// <summary>
        /// Tekstura normalnych
        /// </summary>
        public Texture2D Normal
        {
            get { return this.Parameters["normalTexture"].GetValueTexture2D(); }
            set { this.Parameters["normalTexture"].SetValue(value); }
        }

        /// <summary>
        /// Tekstura wyznaczająca siłę specular w danym miejscu
        /// </summary>
        public Texture2D Specular
        {
            get { return this.Parameters["specularTexture"].GetValueTexture2D(); }
            set { this.Parameters["specularTexture"].SetValue(value); }
        }

        private bool parallaxMapping = false;
        /// <summary>
        /// Czy korzystamy z Parallax Mappingu zamiast Normal Mappingu
        /// </summary>
        public bool ParallaxMapping
        {
            get { return parallaxMapping; }
            set
            {
                parallaxMapping = value;
                this.CurrentTechnique = this.Techniques[(value == true) ? 1 : 0];
            }
        }

        /// <summary>
        /// Konstruktor shadera
        /// </summary>
        /// <param name="content">Menadżer danych</param>
        /// <param name="diffuse">Tekstura diffuse</param>
        public BumpShader(ContentManager content, Texture2D diffuse)
            : base(content.Load<Effect>(ShadersConfig.SHADERS_PATH + @"bump"))
        {
            Diffuse = diffuse;
            this.CurrentTechnique = this.Techniques[0];

            Specular = content.Load<Texture2D>(ShadersConfig.SHADERS_PATH+ @"Textures\white");
            Normal = content.Load<Texture2D>(ShadersConfig.SHADERS_PATH+ @"Textures\zaxis_normal");
        }
    }
}
